package com.zhaoxianglong.priciple;

import org.junit.Test;

/**
 * @program: design-learning
 * @description: 接口隔离原则
 * @author: zhaoxianglong
 * @create: 2021-03-16 14:38
 **/
public class InterficeSegregationTest {

    @Test
    public void testA(){
        A a = new A();
        B b = new B();
        a.depend1(b);
        a.depend2(b);
        a.depend3(b);
    }

    @Test
    public void testB(){
        C c = new C();
        D d = new D();
        c.depend1(d);
        c.depend4(d);
        c.depend5(d);
    }
}


interface Interface1{
    void operation1();
}

interface Interface2{
    void operation2();
    void operation3();
}

interface Interface3{
    void operation4();
    void operation5();
}

class A{
    public void depend1(B i){
        i.operation1();
    }

    public void depend2(B i){
        i.operation2();
    }

    public void depend3(B i){
        i.operation3();
    }
}

class B implements Interface1 , Interface2{

    @Override
    public void operation1() {
        System.out.println("B 实现了 operation1");
    }

    @Override
    public void operation2() {
        System.out.println("B 实现了 operation2");
    }

    @Override
    public void operation3() {
        System.out.println("B 实现了 operation3");

    }
}

class C{

    public void depend1(D i){
        i.operation1();
    }

    public void depend4(D i){
        i.operation4();
    }

    public void depend5(D i){
        i.operation5();
    }
}

class D implements Interface1 , Interface3{

    @Override
    public void operation1() {
        System.out.println("D 实现了 operation1");
    }

    @Override
    public void operation4() {
        System.out.println("D 实现了 operation4");
    }

    @Override
    public void operation5() {
        System.out.println("D 实现了 operation5");
    }
}
